import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { PageContainer, ProTable } from '@ant-design/pro-components';
import '@umijs/max';
import React, { useRef } from 'react';
import { listBiProductsOrderByPageUsingPost } from '@/services/api/biProductsOrderController';

/**
 * BI产品管理页面
 *
 * @constructor
 */
const BiProductsOrderPage: React.FC = () => {
  const actionRef = useRef<ActionType>();

  /**
   * 表格列配置
   */
  const columns: ProColumns<API.BiProductsOrder>[] = [
    {
      title: 'ID',
      dataIndex: 'id',
      valueType: 'text',
      hideInForm: true,
      align: 'center',
    },
    {
      title: '产品ID',
      dataIndex: 'biProduceId',
      valueType: 'text',
      hideInForm: true,
      align: 'center',
    },
    {
      title: '用户ID',
      dataIndex: 'userId',
      valueType: 'text',
      hideInForm: true,
      align: 'center',
    },
    {
      title: '金额',
      dataIndex: 'totalPrice',
      valueType: 'money',
      hideInForm: true,
      align: 'center',
    },
    {
      title: '支付宝单号',
      dataIndex: 'tradeNo',
      valueType: 'text',
      hideInForm: true,
      align: 'center',
    },
    {
      title: '状态',
      dataIndex: 'status',
      valueEnum: {
        0: {
          text: '待支付',
        },
        1: {
          text: '支付成功',
        },
        2: {
          text: '支付超时',
        },
        3: {
          text: '支付失败',
        },
        4: {
          text: '支付异常',
        },
      },
      align: 'center',
    },
    {
      title: '创建时间',
      sorter: true,
      dataIndex: 'createTime',
      valueType: 'dateTime',
      hideInSearch: true,
      hideInForm: true,
      align: 'center',
    },
    {
      title: '更新时间',
      sorter: true,
      dataIndex: 'updateTime',
      valueType: 'dateTime',
      hideInSearch: true,
      hideInForm: true,
      align: 'center',
    },
  ];
  return (
    <PageContainer>
      <ProTable<API.BiProductsOrder>
        headerTitle={'查询表格'}
        actionRef={actionRef}
        rowKey="key"
        search={{
          labelWidth: 120,
        }}
        pagination={{
          pageSize: 10,
        }}
        toolBarRender={() => []}
        request={async (params, sort, filter) => {
          const sortField = Object.keys(sort)?.[0];
          const sortOrder = sort?.[sortField] ?? undefined;

          const { data, code } = await listBiProductsOrderByPageUsingPost({
            ...params,
            sortField,
            sortOrder,
            ...filter,
          } as API.BiProductsOrderQueryRequest);

          return {
            success: code === 0,
            data: data?.records || [],
            total: Number(data?.total) || 0,
          };
        }}
        columns={columns}
      />
    </PageContainer>
  );
};
export default BiProductsOrderPage;
